<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class ClearFilesCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'clear:files';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '清理临时文件';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $path = config('task.path', '/home/workspace/') . 'public/csvs/';
        $cmd = 'find ' . $path . ' -name "*.csv" -mtime +30 | xargs -I file mv file /tmp/csvs';
        exec('mkdir -p  /tmp/csvs');
        exec($cmd);
        return 0;
    }
}
